<?php
namespace api\controllers\actions;

use Yii;

/**
 * Created by PhpStorm.
 * User: zhiyuan
 * Date: 17/11/20
 * Time: 下午3:32
 */

class IndexAction extends \yii\rest\IndexAction
{
    /**
     * 重写渲染数据，按id倒序摆列
     * @name: prepareDataProvider
     * @return \yii\data\ActiveDataProvider
     * @author: rickeryu <lhyfe1987@163.com>
     * @time: 17/11/20 下午4:07
     */
    protected function prepareDataProvider()
    {
        if( !Yii::$app->request->get('sort') ){
            Yii::$app->getRequest()->setBodyParams(['sort'=>'-created_at']);
        }
        $result = parent::prepareDataProvider();
        $result->query->andWhere(['status'=>10]);
        return $result;
    }
}